package sy10_1;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        // 创建ServerSocket对象,监听8888端口
        ServerSocket serverSocket = new ServerSocket(8888);
        // 调用ServerSocket的accept()方法等待客户端的socket
        Socket client = serverSocket.accept();
        // 获取客户端的输出流
        OutputStream os = client.getOutputStream();
        // 当客户端连接到服务端时，向客户端输出数据
        os.write(("欢迎你连接服务器！").getBytes());

        // 关闭输出流
        os.close();
        //关闭Socket
        client.close();

    }
}

